package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.widget.KingPoint;

import java.util.List;

/**
 * Created by King on 2017-05-16
 */

public class DetectionResultPointAdapter extends BaseRecyclerAdapter<Long,DetectionResultPointAdapter.PointHolder> {
    private int index = 0 ;
    public DetectionResultPointAdapter(Context context, List data) {
        super(context, data);
    }

    public DetectionResultPointAdapter(Context context, List data, boolean slideEnabled, boolean reboundEnabled) {
        super(context, data, slideEnabled, reboundEnabled);
    }

    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public void onBindViewHolder(PointHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.tvTitleHigh.setText("" + data.get(position));
        holder.tvTitleLow.setText("" + data.get(position));
        if(position < index){
            holder.tvTitleHigh.setVisibility(View.VISIBLE);
            holder.tvTitleLow.setVisibility(View.GONE);
            holder.kingPoint.setPointType(0);
            holder.leftLine.setVisibility(View.VISIBLE);
            holder.rightLine.setVisibility(View.VISIBLE);
        }else if(position == index){
            holder.tvTitleHigh.setVisibility(View.GONE);
            holder.tvTitleLow.setVisibility(View.VISIBLE);
            holder.kingPoint.setPointType(1);
            holder.leftLine.setVisibility(View.VISIBLE);
            holder.rightLine.setVisibility(View.GONE);
        }else{
            holder.tvTitleHigh.setVisibility(View.VISIBLE);
            holder.tvTitleLow.setVisibility(View.GONE);
            holder.kingPoint.setPointType(2);
            holder.leftLine.setVisibility(View.GONE);
            holder.rightLine.setVisibility(View.GONE);
        }
    }

    @Override
    public PointHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new PointHolder(View.inflate(mContext, R.layout.item_detection_result_recycler,null));
    }

    public class PointHolder extends BaseRecyclerAdapter.ViewHolder {
        private TextView tvTitleHigh, tvTitleLow;
        private KingPoint kingPoint;
        private View leftLine,rightLine;
        public PointHolder(View itemView) {
            super(itemView);
            tvTitleHigh = (TextView) itemView.findViewById(R.id.tv_item_title_high);
            tvTitleLow = (TextView) itemView.findViewById(R.id.tv_item_title_low);
            kingPoint = (KingPoint) itemView.findViewById(R.id.kingpoint_item);
            leftLine = itemView.findViewById(R.id.view_item_left_line);
            rightLine = itemView.findViewById(R.id.view_item_right_line);
        }
    }
}
